<?php
global $_RQ,$_AR;
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
if($_RQ['wxgid']){
	$id=pdo_getcolumn('core_account_wxapp',array('id'=>$_RQ['wxgid'],'uniacid'=>$_SESSION['uniacid']),'plugin_key');
}
if(!$id){
	$id=intval($_RQ['id'])?:intval($_RQ['merchid']);
}
if($_RQ['op']=='list'){
	$id=$id?:$_SESSION['merchid'];
	if(!$id){
		$store=pdo_get('jy_merch_user',array('mid'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid']));
		if(empty($store['id'])){
			exi('您还未注册店铺','error','jy_newpaimerch/register/');
		}
	}else{
		$store=pdo_get('jy_merch_user',array('id'=>$id));
	}
	if($store['id']){
		$_SESSION['merchid']=$store['id'];
	}
	model('jy_weishop/member')->checklogin('','','',$store['id']);
	model('jy_merch/member')->up_catefans($store['id']);
	model('jy_merch/member')->up_addmember($store['id']);
	$return['merchmember']=pdo_get('jy_merch_member',array('merchid'=>$store['id'],'mid'=>$_SESSION['uid']));
	$return['member']=cfc('core')->member_show($_SESSION['uid']);
	$return['goodsnum']=pdo_count('jy_weishop_goods',array('merchid'=>$id));
	$return['ordernum']=pdo_count('jy_weishop_order',array('merchid'=>$id));
	$store['address2']=$store['address'];
	//$store['address']=$store['address']?cfc('tools')->substr($store['address'],0,16).'****':'无地址';
	$store['address']=$store['address']?:'无地址';
	$store['mobile2']=$store['mobile'];
	$store['mobile']=$store['mobile']?cfc('tools')->substr($store['mobile'],0,7).'****':'无电话';
	$store['realname']=$store['realname']?cfc('tools')->substr($store['realname'],0,1).'***':'无';
	$store['lat_lng']=json_decode($store['lat_lng'],true);
	$store['pingjianum']=pdo_count('jy_merch_comments',array('uniacid'=>$_SESSION['uniacid'],'merchid'=>$store['id']),'id');
	$store['grouptitle']=pdo_getcolumn('jy_merch_category',array('uniacid'=>$_SESSION['uniacid'],'id'=>$store['cateid']),'catename');
	$store['islike']=pdo_getcolumn('jy_merch_like_log',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid'],'merchid'=>$store['id']),'id');
	$store['islike']=$store['islike']?1:0;
	$store['topimg']=tomedia($store['topimg']);
	$store['pcd']=json_decode($store['pcd'],true);
	$store['address']=$store['pcd']['city'].' '.$store['pcd']['district'].' '.$store['pcd']['street'].' '.$store['address'];
	$return['store']=$store;
	$cityid=$this->model('city')->upcity($store['pcd']['city'],$store['pcd']);
	$_RQ['cityid']=$cityid;
	$city=$this->model('city')->gocity($_RQ);
	$return['pcd']=$city['pcd'];
	$return['city']=$city;
	if($store['yuyue_type']!='no' && $store['yuyue_type']){
		$return['params']=array('order'=>'goods','merchid'=>$id);
	}else{
		$return['params']=array('order'=>'goods','merchid'=>$id);
	}
	$pindex = max(1, 1);
	$psize = 6;
	$params=array('uniacid'=>$_SESSION['uniacid'],'status'=>1,'nochecked'=>0,'merchid'=>$store['id'],'type <>'=>4);
	$fields=array('id','title','price','image','unit','originalprice','nochecked');
	$goods=pdo_getslice('jy_weishop_goods',$params,array($pindex,$psize),$total,$fields,'','salenum desc, id desc');
	foreach($goods as &$gv){
		$gv['image']=tomedia($gv['image']);
		$gv['originalprice']=$gv['originalprice']?:$gv['price']*1.2;
			$gv['originalprice']=price($gv['originalprice']);
			$v['tags']=pdo_getcolumn('jy_weishop_goods_comments',array('uniacid'=>$_SESSION['uniacid'],'goodsid'=>$gv['id']),'tags');
	}
	$return['tuigoods']=$goods;
	$return['nowh'] = intval(date('H'));
	if($this->plugin_exists('jy_mfuwu')){
		$return['jy_mfuwu']=1;
	}
	if($this->plugin_exists('jy_yuyue')){
		$return['jy_yuyue']=1;
	}
	if($this->plugin_exists('jy_mbaoming')){
		$return['jy_mbaoming']=1;
	}
	$return['id']=$id;
	$title=$store['merchname'];
	$desc=$store['desc'];
	$logo=$store['logo'];
	$sharelink='jy_newpaimerch/merch//id='.$_SESSION['merchid'].'&fromuser='.$_SESSION['uid'];
	$return['sharedata']=array(
			'title'=>$title?:'商户信息-商城',
			'desc'=>$desc?:'商户信息！',
			'link'=>custom_url($sharelink,true),
			'imgUrl'=>tomedia($logo),
	);
	set_html('title',$title?:'商户信息');
	exi($return);
}
if($_RQ['op']=='getyuyue'){
	$merchid=intval($_RQ['merchid']);
	$bankuai_id=intval($_RQ['bankuai_id']);
	$params=array('uniacid'=>$_SESSION['uniacid'],'status'=>1,'merchid'=>$merchid);
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	if($_RQ['num']){
		$psize=$_RQ['num'];
	}
	$total='';
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$total='';
	$fields=array('id','title','group_id','status','busy','image','scanningnum');
	$list=pdo_getslice('jy_weishop_table',$params,array($pindex,$psize),$total,$fields,'','id desc');
	foreach($list as &$itemv){
		$group = pdo_get('jy_weishop_table_group',array('uniacid'=>$_SESSION['uniacid'],'id'=>$itemv['group_id']));
		$itemv['groupname']=$group['title'];
		$itemv['money']=$group['money'];
		$itemv['pay']=$group['pay'];
	}
	$return['list']=$list;
	exi($return);
}
if($_RQ['op']=='getzhaopin'){
	if(!$this->plugin_exists('jy_zhaopin')){
		exi(array('list'=>array()));
	}
	$merchid=intval($_RQ['merchid']);
	$merchmid= pdo_getcolumn('jy_merch_user',array('uniacid'=>$_SESSION['uniacid'],'id'=>$merchid),'mid');
	$params=array('uniacid'=>$_SESSION['uniacid'],'mid'=>$merchmid);
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	if($_RQ['num']){
		$psize=$_RQ['num'];
	}
	$total='';
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$total='';
	$list=pdo_getslice('jy_zhaopin_job',$params,array($pindex,$psize),$total,$fields,'','id desc');
	foreach($list as &$itemv){
		$itemv['groupname']=$itemv['type']=1?'求职':'招聘';
		$itemv['money']=$group['money'];
		$itemv['pay']=$group['pay'];
	}
	$return['list']=$list;
	exi($return);
}
if($_RQ['op']=='getfuwu'){
	if(!$this->plugin_exists('jy_yuyue')){
		exi(array('list'=>array()));
	}
	$merchid=intval($_RQ['merchid']);
	$bankuai_id=intval($_RQ['bankuai_id']);
	$params=array('uniacid'=>$_SESSION['uniacid'],'status'=>1,'merchid'=>$merchid);
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	if($_RQ['num']){
		$psize=$_RQ['num'];
	}
	$total='';
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$total='';
	$fields=array('id','uniacid','worker_id','title','status','image','remark','price','work_time','serve_time','times','cancel_time','isshow','paixu','createtime');
	$list=pdo_getslice('jy_yuyue_serve',$params,array($pindex,$psize),$total,$fields,'','id desc');
	foreach($list as &$itemv){
		$group = pdo_get('jy_weishop_table_group',array('uniacid'=>$_SESSION['uniacid'],'id'=>$itemv['group_id']));
		$itemv['groupname']=$group['title'];
		$itemv['money']=$group['money'];
		$itemv['pay']=$group['pay'];
	}
	$return['list']=$list;
	exi($return);
}
?>